package com.alesj.newsfeed.bool.impl;

import java.util.Set;

import com.alesj.newsfeed.bool.Token;
import com.alesj.newsfeed.bool.ConditionCreator;
import com.alesj.newsfeed.bool.Condition;

/**
 * @author <a href="mailto:ales.justin@gmail.com">Ales Justin</a>
 */
public class SimpleToken<C> implements Token<Condition<C>> {

    protected ConditionCreator<C> creator;
    protected String string;

    public SimpleToken(ConditionCreator<C> creator, String string) {
        this.creator = creator;
        this.string = string;
    }

    public Condition<C> value() {
        return new LazyCondition();
    }

    public String toString() {
        return string;
    }

    private class LazyCondition implements Condition<C> {
        public Set<C> execute() {
            Condition<C> condition = creator.createCondition(string);
            return condition.execute();
        }
    }
}
